//
//  ZGSViewController.m
//  Tour
//
//  Created by dllo on 15/10/30.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ZGSViewController.h"
#import "AdvanceEdit.h"
#import "ZGSHotModelTwo.h"
#import "ZGSTableViewCell.h"
@interface ZGSViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *arr;

@end

@implementation ZGSViewController

- (void)dealloc{
    [_arr release];
    [_tableView release];
    [_cithId release];
    [_type release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"精选";
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.tableView registerClass:[ZGSTableViewCell class] forCellReuseIdentifier:@"reuse"];
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.rowHeight = HEIGHT / 3.5;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.arr =[NSMutableArray array];
    [self creatData];
}

- (void)creatData{
//    NSString *tmp = [NSString stringWithFormat:@"%@", self.type];
    NSString *urlStr = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/trips/", self.type, self.cithId];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
//        NSLog(@"%@", dic);
        self.arr = [ZGSHotModelTwo baseModelArr:dic[@"items"]];
        NSLog(@"%@", self.arr);
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZGSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    NSString *strGo = [NSString stringWithFormat:@"%@人去过", [self.arr[indexPath.row] waypoints]];
    cell.labelGo.text = strGo;
    NSString *strLike = [NSString stringWithFormat:@"%@人喜欢", [self.arr[indexPath.row] recommendations]];
    [cell.viewImage sd_setImageWithURL:[NSURL URLWithString:[self.arr[indexPath.row] cover_image_1600]] placeholderImage:[UIImage imageNamed:@"10.jpeg"]];
    cell.labelLike.text = strLike;
    cell.labelTitle.text = [self.arr[indexPath.row] name];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
